package com.Reporte_Evolutivo;

import java.util.ArrayList;

import com.Adapter.ImageAdapter_Eventos;
import com.Adapter.ImageAdapter_dinamico;
import com.BD.BD_SQLite;
import com.BD.Tabla_Evento;
import com.reportes.Imagen_Nombre;
import com.reportes.R;
import com.reportes.R.drawable;
import com.reportes.R.id;
import com.reportes.R.layout;

import android.app.ActionBar;
import android.app.Activity;
import android.app.ActionBar.LayoutParams;
import android.app.ActionBar.OnMenuVisibilityListener;
import android.app.ActionBar.OnNavigationListener;
import android.app.ActionBar.Tab;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SpinnerAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class RE_3_Muestra_Eventos extends Activity{
	

	private String idSubtipo;	
	
	public GridView gridviewSubTipos;
	ArrayList<Tabla_Evento> tsb = new ArrayList();
	public BD_SQLite db = null;
			
	//public ImageAdapter_dinamico imAd = new ImageAdapter_dinamico(this,mThumbIds);
	
	public void onCreate(Bundle savedInstanceState) {
		
		idSubtipo= this.getIntent().getExtras().getString("idSubtipo");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.re_3_muestra_eventos);
        
		Resources res = getResources();
		Drawable myImage = res.getDrawable(R.drawable.background2);		
		ActionBar actionBar = this.getActionBar();
		actionBar.setBackgroundDrawable(myImage);
		actionBar.setDisplayUseLogoEnabled(true);
		actionBar.setDisplayShowTitleEnabled(false);
		
		gridviewSubTipos = (GridView)findViewById(R.id.grid_eventos);
		db = new BD_SQLite(this);//se obtiene la referencia a la abse de datos
	
		tsb = db.getEventos(idSubtipo);
		
		if (tsb.size()==0) {
        	Toast.makeText(this, "No existe ningún Evento. Retroceder y elegir otro Subtipo.", Toast.LENGTH_SHORT).show();
        	
        }else{
        	ImageAdapter_Eventos adapter = new ImageAdapter_Eventos(tsb, this);	
    		
    		gridviewSubTipos.setAdapter(adapter);
    		gridviewSubTipos.setOnItemClickListener(new OnItemClickListener()
    	    {
    			@Override
    			public void onItemClick(AdapterView<?> adapter, View v, int position,long id) {
    				// TODO Auto-generated method stub
    				//TablaSubtipo SubTipo = (TablaSubtipo)adapter.getItemAtPosition(position);				
    				Intent intent = new Intent(RE_3_Muestra_Eventos.this,RE_4_Genera_Reporte.class);
    		    	//intent.putExtra("idSubtipo",String.valueOf(SubTipo.getIdSubTipo()));		    	
    		    	startActivity(intent);
    			}	    	
    	    });
        	
        }   
	   	
      }	
	

}
